package com.atguigu.gmall.list.rpc.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.list.service.GoodsService;
import com.atguigu.gmall.model.list.Goods;
import com.atguigu.gmall.model.list.SearchParam;
import com.atguigu.gmall.model.list.SearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/inner")
@RestController
public class GoodsController {


    @Autowired
    GoodsService goodsService;

    @PostMapping("/onsale/goods")
    public Result onSaleGoods(@RequestBody Goods goods){

        goodsService.onsale(goods);
        return Result.ok();
    }

    @DeleteMapping("/canclesale/goods/{skuId}")
    public Result cancleSaleGoods(@PathVariable("skuId")Long skuId){

        goodsService.cancleSale(skuId);
        return Result.ok();
    }

    @PostMapping("/search/goods")
    public SearchResponseVo searchGoods(@RequestBody SearchParam param){

        // 检索
        SearchResponseVo responseVo =  goodsService.search(param);

        return responseVo;
    }

    @PutMapping("/updatescore/{skuId}/{score}")
    public Result updateGoodsHotScore(@PathVariable("skuId") Long skuId,
                                      @PathVariable("score") Long score){

        goodsService.updateGoodsHotScore(skuId,score);
        return Result.ok();
    }
}
